package com.vr.xuecheng.content.controller;

import cn.hutool.core.lang.tree.Tree;
import com.vr.xuecheng.base.response.Result;
import com.vr.xuecheng.content.model.dto.AddOrUpdateTeachPlanParamsDTO;
import com.vr.xuecheng.content.model.dto.TeachPlanMediaDTO;
import com.vr.xuecheng.content.model.dto.TeachPlanOfFeignDTO;
import com.vr.xuecheng.content.model.entity.TeachPlan;
import com.vr.xuecheng.content.service.ITeachPlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author hsh
 */
@Slf4j
@RestController
@Tag(name = "课程计划")
@RequestMapping("/teachplan")
@RequiredArgsConstructor
public class TeachPlanController {

    private final ITeachPlanService teachPlanService;

    /**
     * @param courseId 课程id
     * @return {@code TeachPlanWithTreeVO } 结果
     * 通过课程id获取课程计划以树形结构展示
     */
    @Operation(summary = "获取课程计划树形结构")
    @GetMapping("/{id}/tree-nodes")
    public List<Tree<Long>> getTreeNodesById(@PathVariable("id") Long courseId) {
        return teachPlanService.getTreeNodesById(courseId);
    }

    /**
     * @param req 新增或这更新参数
     * @return {@code Result<String> } 结果
     * 新增或者修改课程计划
     */
    @PostMapping
    @Operation(summary = "新增或修改课程计划")
    public Result<String> addOrUpdateTeachPlan(@RequestBody AddOrUpdateTeachPlanParamsDTO req) {
        return teachPlanService.addOrUpdateTeachPlan(req);
    }

    /**
     * @param id 课程计划id
     * @return {@code Result<String> } 结果
     * 删除课程计划
     */
    @Operation(summary = "删除课程计划")
    @DeleteMapping("/{id}")
    public Result<String> deleteTeachPlan(@PathVariable("id") Long id) {
        return Result.toResult(teachPlanService.removeById(id));
    }

    /**
     * @param id 课程计划id
     * @return {@code String } 结果
     * 上移课程计划
     */
    @Operation(summary = "上移课程计划")
    @PostMapping("/moveup/{id}")
    public Result<String> moveUp(@PathVariable("id") Long id) {
        return teachPlanService.moveUp(id);
    }

    /**
     * @param id 课程计划id
     * @return {@code String } 结果
     * 下移课程计划
     */
    @Operation(summary = "下移课程计划")
    @PostMapping("/movedown/{id}")
    public Result<String> moveDown(@PathVariable("id") Long id) {
        return teachPlanService.moveDown(id);
    }


    /**
     * @param req 关联媒资参数
     * @return {@code Result<String> } 结果
     * 教学计划关联媒资信息
     */
    @Operation(summary = "教学计划关联媒资信息")
    @PostMapping("/association/media")
    public Result<String> relevanceMedia(@RequestBody TeachPlanMediaDTO req) {
        return Result.toResult(teachPlanService.relevanceMedia(req));
    }
    @Operation(summary = "通过id获取教学计划")
    @GetMapping("/{teachplanId}")
    public TeachPlanOfFeignDTO getTeachPlanById(@PathVariable("teachplanId") Long teachplanId) {
        TeachPlan teachPlan = teachPlanService.getById(teachplanId);
        TeachPlanOfFeignDTO teachPlanOfFeignDTO = new TeachPlanOfFeignDTO();
        teachPlanOfFeignDTO.setId(teachPlan.getId());
        teachPlanOfFeignDTO.setPname(teachPlan.getPname());
        return teachPlanOfFeignDTO;
    }

}
